
<#include "/base/common/head.html"/>

<div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
			<table  width="100%">
        	 	<tr style="height: 30px;">
	           		<th><span>名称：</span></th>
		            <td><span class="valueSpan"><pre>${curd.name!''}</pre></span></td>
	           		<th><span>bo类：</span></th>
		            <td><span class="valueSpan"><pre>${curd.boPath!''}</pre></span></td>
            	</tr>
            	<tr style="height: 30px;">
	           		<th><span>String注意事项：</span></th>
		            <td colspan="3"><span class="valueSpan"><pre>（1）下拉框-固定序列、下拉框多选-固定序列：“参数--固定序列” 必填。（2）下拉框-URL、下拉框多选-URL：“下拉URL”、“参数--URL取值属性” 必填。</pre></span></td>
            	</tr>
        	</table>
        </div>
        
        <div style="text-align: left; margin:6px; display:none;">
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" onclick="update()">编辑</a>
        </div>
</div>


			<table id="dg" class="easyui-datagrid"
                    data-options="
                    	fit:true,
                    	rownumbers:true,
                        border: false,
                        toolbar: '#tb',
                        url: 'findCurdFieldByCurdId?curdId=${curd.id}',
    					striped:true, //是否显示斑马线
                        method: 'get',
                        onLoadSuccess:update
                    ">
                <thead>
                    <tr>
                        <th data-options="field:'fieldName', align:'center',width:100" rowspan="2">属性</th>
                        <th data-options="field:'showName', align:'center',width:80,editor:{type:'textbox',options:{required:true}}" rowspan="2">显示名称</th>
                        <th colspan="9">列表页面</th>
                        <th colspan="10">增加页面</th>
                        <th colspan="2">修改页面</th>
                        <th colspan="2">详情页面</th>
                        
                    </tr>
                    <tr>
                        <th data-options="field:'showInList',align:'center',width:40,editor:{type:'checkbox'}">列表<br/>显示</th> 
                        <th data-options="field:'sn', align:'center',width:40,editor:{type:'numberbox',options:{required:true}}">列表<br/>序号</th>              
                        <th data-options="field:'listWidth',align:'center',width:40,editor:{type:'numberbox',options:{required:true}}">列宽</th>   
                        <th data-options="field:'listAlign', align:'center',width:70,
                        		editor:{
                                    type:'combobox',
                                    options:{
                                        valueField:'value',
                                        textField:'text',
                                        editable:false,
                                        data: [{value:'center', text:'居中'}, 
                                        		{value:'left', text:'左对齐'},
                                        	   {value:'right', text:'右对齐'}
                                        	  ],
                                        required:true
                                    }
                                }">对齐方式</th>  
                        <th data-options="field:'listSortable',align:'center',width:40,editor:{type:'checkbox'}">允许<br/>排序</th>   
                        <th data-options="field:'canSum',align:'center',width:40,editor:{type:'checkbox'}">允许<br/>合计</th>  
                        <th data-options="field:'sumTitle',align:'center',width:40,editor:{type:'checkbox'}">合计<br/>标题</th>  
                        <th data-options="field:'canSearch',align:'center',width:40,editor:{type:'checkbox'}">查询<br/>条件</th>   
                        <th data-options="field:'excelType',align:'center',width:40,editor:{type:'checkbox'}">Excel<br/>分表</th>   
                      
                        <th data-options="field:'showInAdd',align:'center',width:40,editor:{type:'checkbox'}">允许<br/>增加</th>
                        <th data-options="field:'addRequired',align:'center',width:40,editor:{type:'checkbox'}">必填</th>
                        <th data-options="field:'snAdd', align:'center',width:80,editor:{type:'numberbox'}">增加序号<br/>
                        	<a id="btn" href="javascript:void(0)" class="easyui-linkbutton color1" onclick="copySn_add()" >参考列表</a>  
                        </th>  
                        <th data-options="field:'fieldName', align:'center',width:100" >属性</th>
                        <th data-options="field:'fieldType', align:'center',width:90 ,formatter:formatFieldType" >属性类型</th>
                        <th data-options="field:'addType', align:'center',width:130,
                        		editor:{
                                    type:'combobox',
                                    options:{
                                        valueField:'value',
                                        textField:'text',
                                        editable:false,
                                        required:true
                                    }
                                },formatter:formatAddType">录入组件</th>
                        <th data-options="field:'addSelectUrl', align:'center',width:150,editor:{type:'textbox'}">下拉URL</th>
                        <th data-options="field:'parameter', align:'left',width:130,editor:{type:'textbox'}">参数，用途说明：<br/>String：固定序列<br/>String：URL取值属性<br/>其他bo：URL显示属性<br/>Boolean：true显示值</th>
                        <th data-options="field:'falseShow', align:'center',width:100,editor:{type:'textbox'}">false显示值</th>
                        <th data-options="field:'defaultValue',align:'center',width:80,editor:{type:'textbox'}">默认值</th>
                        
                        <th data-options="field:'showInUpdate',align:'center',width:40,editor:{type:'checkbox'}">允许<br/>编辑</th>
                        <th data-options="field:'snUpdate', align:'center',width:80,editor:{type:'numberbox'}">编辑序号<br/>
                        	<a id="btn" href="javascript:void(0)" class="easyui-linkbutton color1" onclick="copySn_update()" >参考增加</a>  
                        </th>  
                                
                        <th data-options="field:'showInDetail',align:'center',width:40,editor:{type:'checkbox'}">详情<br/>显示</th>
                        <th data-options="field:'snDatail', align:'center',width:80,editor:{type:'numberbox'}">详情序号<br/>
                        	<a id="btn" href="javascript:void(0)" class="easyui-linkbutton color1" onclick="copySn_detail()" >参考增加</a>  
                        </th> 
                        
                        
                    </tr>
                </thead>
            </table>
            
<style type="text/css">

.l-btn {
    border-radius: 5px;
    padding: 0px 0px 0px 0px;
}


</style>	
		
<script>
top.window.subPage.save = save;
function save(successFunc) {
	//验证必填
	var validateResult = true;
	var rows = $("#dg").datagrid("getRows");
	for(var i = 0; i < rows.length; i++)
	{
		 if (!$('#dg').datagrid('validateRow', i))
		 {
             validateResult = false;
             break;
         }
    }

	if(validateResult) 
	{
		$('#dg').datagrid('acceptChanges'); //将编辑框中的值写入rows中
		
		//提交前，对布尔型进行转换，以避免后台gson转换时报错
		for(var i = 0; i < rows.length; i++)
		{
			var row = rows[i];
			if(row.showInList == 1){row.showInList = true;} else{row.showInList = false;}
			if(row.showInAdd == 1){row.showInAdd = true;} else{row.showInAdd = false;}
			if(row.showInUpdate == 1){row.showInUpdate = true;} else{row.showInUpdate = false;}
			if(row.showInDetail == 1){row.showInDetail = true;} else{row.showInDetail = false;}
			if(row.canSum == 1){row.canSum = true;} else{row.canSum = false;}
			if(row.sumTitle == 1){row.sumTitle = true;} else{row.sumTitle = false;}
			if(row.canSearch == 1){row.canSearch = true;} else{row.canSearch = false;}
			if(row.excelType == 1){row.excelType = true;} else{row.excelType = false;}
			if(row.listSortable == 1){row.listSortable = true;} else{row.listSortable = false;}
			if(row.addRequired == 1){row.addRequired = true;} else{row.addRequired = false;}
	    }
		
		var param = getParam();
		param.arrStr = JSON.stringify(rows);
		$.post("sonConfig", param, function(data){
			if("01" == data.code){//成功
				top.window.closeWindow(); //关闭窗口
				top.window.subPage.loadCurrDatagrid(); //回调方法
				showMsg(data.msg); //显示消息
				
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
				update();
			}
		});
	}
	else
	{
		showWarnMsg("请输入必填项！");
	}
}

function getParam() {
	return {
		"id": ${curd.id},
	}
}

//编辑配置
function update()
{
	var rows = $("#dg").datagrid("getRows");
	for(var i = 0; i < rows.length; i++) {
        $('#dg').datagrid('beginEdit', i);
    }
	setInput();
}

//录入组件配置
function setInput()
{
	var rows = $("#dg").datagrid("getRows");

	//属性类型
	var type_String ="java.lang.String";
	var type_Integer ="java.lang.Integer";
	var type_Byte ="java.lang.Byte";
	var type_Short ="java.lang.Short";
	var type_Long ="java.lang.Long";
	var type_Double ="java.lang.Double";
	var type_Float ="java.lang.Float";
	var type_Boolean ="java.lang.Boolean";
	var type_Date ="java.util.Date";
	
	//录入组件类型
	var data_String = [{value:'00', text:'默认'}, 
      		{value:'S01', text:'文本框'},
       	    {value:'S02', text:'文本区域'},
       	    {value:'S11', text:'下拉框-固定序列'},
       	    {value:'S12', text:'下拉框-URL'},
       	    {value:'S21', text:'下拉框多选-固定序列'},
       	    {value:'S22', text:'下拉框多选-URL'}
       	  ];
	
	var data_Integer = [{value:'00', text:'默认'}, 
       	    {value:'I01', text:'整数输入'},
       	    {value:'I02', text:'整数微调'}
       	  ];
	
	var data_Double = [{value:'00', text:'默认'}, 
       	    {value:'D01', text:'实数输入'}
       	  ];
	
	var data_Boolean = [{value:'00', text:'默认'}, 
       	    {value:'B01', text:'开关'}
       	  ];
	
	var data_Date = [{value:'00', text:'默认'}, 
       	    {value:'DT01', text:'日期选择'},
       	    {value:'DT02', text:'日期微调'},
       	    {value:'DT03', text:'时间选择'},
       	    {value:'DT04', text:'时间微调'}
       	  ];
	
	var data_BO = [{value:'00', text:'默认'},
       	    {value:'BO01', text:'下拉框'},
       	    {value:'BO02', text:'下拉列表'}
       	  ];
	
	//设置
	for(var i = 0; i < rows.length; i++) 
	{
		var row = rows[i];
		var fieldType = row.fieldType;
		var otherBo = row.otherBo;
		
		//设置录入组件
		var ed = $('#dg').datagrid('getEditor', {index:i,field:'addType'});
		if(fieldType == type_String)
		{
			$(ed.target).combobox('loadData', data_String);
		}
		else if(fieldType == type_Integer || fieldType == type_Byte || fieldType == type_Short || fieldType == type_Long )
		{
			$(ed.target).combobox('loadData', data_Integer);
			
		}
		else if(fieldType == type_Double || fieldType == type_Float)
		{
			$(ed.target).combobox('loadData', data_Double);
		}
		else if(fieldType == type_Boolean)
		{
			$(ed.target).combobox('loadData', data_Boolean);
		}
		else if(fieldType == type_Date)
		{
			$(ed.target).combobox('loadData', data_Date);
		}
		else if(otherBo)
		{
			$(ed.target).combobox('loadData', data_BO);
			
			//URL 必填
			var addSelectUrl_ed = $('#dg').datagrid('getEditor', {index:i,field:'addSelectUrl'});
			$(addSelectUrl_ed.target).textbox({'required':true});
			
			//显示属性 必填
			var parameter_ed = $('#dg').datagrid('getEditor', {index:i,field:'parameter'});
			$(parameter_ed.target).textbox({'required':true});
		}

		//非数值型不允许合计
		if(!(fieldType == type_Integer || fieldType == type_Byte || fieldType == type_Short || fieldType == type_Long || fieldType == type_Double || fieldType == type_Float))
		{
			var canSum_ed = $('#dg').datagrid('getEditor', {index:i,field:'canSum'});
			$(canSum_ed.target).hide();
		}
		
		//不允许作为查询条件
		if(!(fieldType == type_String || fieldType == type_Date || otherBo))
		{
			var canSearch_ed = $('#dg').datagrid('getEditor', {index:i,field:'canSearch'});
			$(canSearch_ed.target).hide();
		}
		
		//不允许作为Excel分表条件
		if(!(fieldType == type_String || otherBo))
		{
			var excelType_ed = $('#dg').datagrid('getEditor', {index:i,field:'excelType'});
			$(excelType_ed.target).hide();
		}

		//不允许作为合计标题
		if( fieldType == type_Boolean || otherBo)
		{//这类数据列都必须格式化
			var sumTitle_ed = $('#dg').datagrid('getEditor', {index:i,field:'sumTitle'});
			$(sumTitle_ed.target).hide();
		}
		
		//非bo、非String,不填写‘下拉URL’
		if(!otherBo && fieldType != type_String)
		{
			var addSelectUrl_ed = $('#dg').datagrid('getEditor', {index:i,field:'addSelectUrl'});
			$(addSelectUrl_ed.target).textbox('destroy');
		}

		//非bo、非String、非Boolean,不填写‘参数’
		if(!otherBo && fieldType != type_String && fieldType != type_Boolean)
		{
			var parameter_ed = $('#dg').datagrid('getEditor', {index:i,field:'parameter'});
			$(parameter_ed.target).textbox('destroy');
		}

		//非Boolean,不填写‘false显示值’
		if(fieldType != type_Boolean)
		{
			var falseShow_ed = $('#dg').datagrid('getEditor', {index:i,field:'falseShow'});
			$(falseShow_ed.target).textbox('destroy');
		}
		else
		{
			//true显示值 必填
			var parameter_ed = $('#dg').datagrid('getEditor', {index:i,field:'parameter'});
			$(parameter_ed.target).textbox({'required':true});
			
			//true显示值 必填
			var falseShow_ed = $('#dg').datagrid('getEditor', {index:i,field:'falseShow'});
			$(falseShow_ed.target).textbox({'required':true});
		}

		//不允许填写默认值
		if(fieldType == type_Date)
		{
			var defaultValue_ed = $('#dg').datagrid('getEditor', {index:i,field:'defaultValue'});
			$(defaultValue_ed.target).textbox('destroy');
		}
  }
}

//copy序号（列表序号-->增加序号）
function copySn_add()
{
	var rows = $("#dg").datagrid("getRows");
	for(var i = 0; i < rows.length; i++)
	{
		var ed_from = $('#dg').datagrid('getEditor', {index:i,field:'sn'}); //开始编辑器
		var ed_to = $('#dg').datagrid('getEditor', {index:i,field:'snAdd'}); //到过编辑器
		
		var sn = $(ed_from.target).numberbox('getValue'); //取值
		$(ed_to.target).numberbox('setValue',sn); //赋值
    }
}

//copy序号（增加序号-->编辑序号）
function copySn_update()
{
	var rows = $("#dg").datagrid("getRows");
	for(var i = 0; i < rows.length; i++)
	{
		var ed_from = $('#dg').datagrid('getEditor', {index:i,field:'snAdd'}); //开始编辑器
		var ed_to = $('#dg').datagrid('getEditor', {index:i,field:'snUpdate'}); //到过编辑器
		
		var sn = $(ed_from.target).numberbox('getValue'); //取值
		$(ed_to.target).numberbox('setValue',sn); //赋值
    }
}

//copy序号（增加序号-->详情序号）
function copySn_detail()
{
	var rows = $("#dg").datagrid("getRows");
	for(var i = 0; i < rows.length; i++)
	{
		var ed_from = $('#dg').datagrid('getEditor', {index:i,field:'snAdd'}); //开始编辑器
		var ed_to = $('#dg').datagrid('getEditor', {index:i,field:'snDatail'}); //到过编辑器
		
		var sn = $(ed_from.target).numberbox('getValue'); //取值
		$(ed_to.target).numberbox('setValue',sn); //赋值
  }
}

//格式化：Boolean
function formatBoolean(value)
{
	if(value == null)
	{
		return "";
	}
	if(value)
	{
		return "是";
	}
	return "";
	
}

//格式化：属性类型
function formatFieldType(value)
{
	var arr = value.split(".");
	return arr[arr.length-1];
	
}


//格式化：对齐方式
function formatListAlign(value)
{
	if(value == "left")
	{
		return "左对齐";
	}
	if(value == "right")
	{
		return "右对齐";
	}
	return "居中";
}

//格式化：组件类型
function formatAddType(value)
{
	if(value == "S01")
	{
		return "文本框";
	}
	if(value == "S02")
	{
		return "文本下拉框";
	}
	if(value == "S03")
	{
		return "多选";
	}
	if(value == "S04")
	{
		return "多行文本";
	}
	if(value == "I01")
	{
		return "整数输入";
	}
	if(value == "I02")
	{
		return "整数微调";
	}
	if(value == "D01")
	{
		return "实数输入";
	}
	if(value == "B01")
	{
		return "是否";
	}
	if(value == "B02")
	{
		return "开关";
	}
	if(value == "DT01")
	{
		return "日期选择";
	}
	if(value == "DT02")
	{
		return "日期微调";
	}
	if(value == "DT03")
	{
		return "时间选择";
	}
	if(value == "DT04")
	{
		return "时间微调";
	}
	if(value == "T01")
	{
		return "下拉框";
	}
	if(value == "T02")
	{
		return "下拉列表";
	}
	return "默认";
	
}

</script>   
<#include "/base/common/foot.html"/>